#ifndef RTE_KT1282_MASTER_KSERIALFIRMATA_H
#define RTE_KT1282_MASTER_KSERIALFIRMATA_H

#include <kSerial.h>
#include <RingBuffer.h>
#include "Stream.h"
#include <mFirmata.h>

class kSerialFirmata : public kSerial
{
public:
#ifdef ARDUINO

    kSerialFirmata(mFirmata *fm, kSerial *s, int id);

#endif

    int begin(unsigned int i, u8 i1 = SERIAL_8N1, int rx_buff_sz = 256, int tx_buff_sz = 256) override;

#ifndef THIS_IS_BOOTLOADER
    int end() override;
#endif

    int available() override;
    int available_wait(int Delay) override;

    int read() override;

    int write(uint8_t) override;

    int availableForWrite();

    int write(const u8 *string, int i) override;

    int peek() override;

    mFirmata *fm;
    int id;

    int read_wait(int timeout = -1) final;

    void handleSysex(byte i, byte i1, byte *string);

    nStream *fs;
    uint32_t next_tick{};
    void *rx_buff;
};

#endif // RTE_KT1282_MASTER_KSERIALFIRMATA_H
